﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class TH_TN_DB
    {
        public static DataTable SelectTHTN()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spSelectTHTN", con);
                con.Open();
                SqlCommand command = new SqlCommand("spSelectTHTN", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void InsertTHTN(TH_TN newTHTN)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCTTachNhan", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemCTTachNhan", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_TN", newTHTN.MaCT_TN);
                command.Parameters.AddWithValue("@MaLo", newTHTN.Malo);
                command.Parameters.AddWithValue("@MaNhom", newTHTN.Manhom);
                command.Parameters.AddWithValue("@MaTP", newTHTN.MaTP);
                command.Parameters.AddWithValue("@MaDV", newTHTN.MaDV);
                command.Parameters.AddWithValue("@KL_HangVo", newTHTN.KL_hangvo);
                command.Parameters.AddWithValue("@KL_NhanNguyen", newTHTN.Kl_nhannguyen);
                command.Parameters.AddWithValue("@KL_NhanBe", newTHTN.Kl_nhanbe);
                command.Parameters.AddWithValue("@DinhMuc", newTHTN.Dinhmuc);
                command.Parameters.AddWithValue("@NgayGiao", newTHTN.Ngaygiao);
                command.Parameters.AddWithValue("@NgayThuHoi", newTHTN.Ngaythuhoi);
                command.ExecuteNonQuery();

            }
        }
        public static void UpdateTHTN(string oldMaCT_TN, TH_TN newTHTN)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatCTTachNhan", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatCTTachNhan", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_TN", oldMaCT_TN);
                command.Parameters.AddWithValue("@MaLo", newTHTN.Malo);
                command.Parameters.AddWithValue("@MaNhom", newTHTN.Manhom);
                command.Parameters.AddWithValue("@MaTP", newTHTN.MaTP);
                command.Parameters.AddWithValue("@MaDV", newTHTN.MaDV);
                command.Parameters.AddWithValue("@KL_HangVo", newTHTN.KL_hangvo);
                command.Parameters.AddWithValue("@KL_NhanNguyen", newTHTN.Kl_nhannguyen);
                command.Parameters.AddWithValue("@KL_NhanBe", newTHTN.Kl_nhanbe);
                command.Parameters.AddWithValue("@DinhMuc", newTHTN.Dinhmuc);
                command.Parameters.AddWithValue("@NgayGiao", newTHTN.Ngaygiao);
                command.Parameters.AddWithValue("@NgayThuHoi", newTHTN.Ngaythuhoi);
                command.ExecuteNonQuery();
            }
        }
        public static void DeleteTHTN(string oldMaCT_TN)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCTTachNhan", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaCTTachNhan", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaCT_TN", oldMaCT_TN);
                command.ExecuteNonQuery();

            }
        }
    }
}
